package com.example.demo.controller;
/* @Author      zouzh
 * @PackageName transaction-demo
 * @Package     com.example.demo.controller
 * @Date        2023/8/26 17:41
 */

import com.example.demo.model.Userinfo;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.beans.Transient;

@RequestMapping("/user")
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/add")
    @Transactional
    public int add(Userinfo userinfo){
        // 1.非空判断
        Userinfo userinfo1 = new Userinfo();
        userinfo.setId(1);
        userinfo.setName("zhansan");
        // 2.调用 service 执行添加
        int result = userService.add(userinfo);
        System.out.println("result "+ result);
        int num = 10 / 0;
        // 3.将结果返回给前端
        return 0;
    }
}
